/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxt.UI;

import com.cxt.BL.MonitorManifiestoBL;
import com.cxt.Bean.MonitorManifiestoBean;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author jgutierrez
 */
public class FrmTblMonitorManifiesto extends javax.swing.JFrame {

    /**
     * Creates new form FrmTblMonitorManifiesto
     */
    public FrmTblMonitorManifiesto() {
        initComponents();
        
        listarMonitorManifiesto();
        
        Timer timer = new Timer(5*1000, new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                listarMonitorManifiesto();
                
            }
        });
        
        timer.start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblMonitorManifiesto = new javax.swing.JTable();
        lblContador = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tblMonitorManifiesto.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblMonitorManifiesto.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jScrollPane1.setViewportView(tblMonitorManifiesto);

        lblContador.setText("0");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblContador)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblContador)
                .addGap(12, 12, 12)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
                .addContainerGap())
        );

        lblContador.getAccessibleContext().setAccessibleName("lblContador");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void listarMonitorManifiesto() {
        
        Date fecha = new Date();
        DateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        lblContador.setText( "ACTUALIZADO: " + formatoFecha.format(fecha) );
        
        DefaultTableModel tabla = new DefaultTableModel();
        MonitorManifiestoBL objMMBL = new MonitorManifiestoBL();
        ArrayList<MonitorManifiestoBean> lista = new ArrayList();
        lista = objMMBL.listarMonitorManifiesto();
        
        tabla.addColumn("Código Manifiesto");
        tabla.addColumn("Nave");
        tabla.addColumn("Agencia");
        tabla.addColumn("Nro Contenedores");
        tabla.addColumn("Fecha Descarga");
        
        tabla.setRowCount(lista.size());
        
        int i=0;
        for (MonitorManifiestoBean mm:lista){
            tabla.setValueAt(mm.getCodManifiesto(), i, 0);
            tabla.setValueAt(mm.getNave(), i, 1);
            tabla.setValueAt(mm.getAgencia(), i, 2);
            tabla.setValueAt(mm.getNroContenedores(), i, 3);
            tabla.setValueAt(mm.getFechaDescarga(), i, 4);
            i++;
        }
        
        this.tblMonitorManifiesto.setModel(tabla);
        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmTblMonitorManifiesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmTblMonitorManifiesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmTblMonitorManifiesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmTblMonitorManifiesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmTblMonitorManifiesto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblContador;
    private javax.swing.JTable tblMonitorManifiesto;
    // End of variables declaration//GEN-END:variables
}
